package service

import (
	"github.com/gin-gonic/gin"
	"kamibako.ltd/go-essential/internal/service/internal/dao"
	"kamibako.ltd/go-essential/utility/response"
)
var User = sUser{}

type sUser struct {
}

func (s *sUser) Register(c *gin.Context, name, password, telephone string) {
	if len(telephone) != 11 {
		response.Json(c, 422, "手机号码过长或过短")
	}
	if len(password) < 6 {
		response.Json(c, 422, "密码过短")
	}
	if nameLen := len(name); nameLen > 12 || nameLen < 4 {
		response.Json(c, 422, "用户名不符合")
	}
}

func (s *sUser) GetUserById(c *gin.Context, id int) {
	user, err := dao.User.GetUserById(id)
	if err != nil {
		response.Json(c, 422, "用户不存在")
	}
	response.Json(c, 200, "OK", user)
}
